package org.shoukaiseki.common.utils;

import org.shoukaiseki.common.exception.MessageVirtualException;

/**
 *
 **/
public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils{


    /**
     * Checks if any value in the given array is {@code null}.
     *
     * <p>
     * If any of the values are {@code null} or the array is {@code null},
     * then {@code true} is returned, otherwise {@code false} is returned.
     * </p>
     *
     * <pre>
     * ObjectUtils.anyNull(*)             = false
     * ObjectUtils.anyNull(*, *)          = false
     * ObjectUtils.anyNull(null)          = true
     * ObjectUtils.anyNull(null, null)    = true
     * ObjectUtils.anyNull(null, *)       = true
     * ObjectUtils.anyNull(*, null)       = true
     * ObjectUtils.anyNull(*, *, null, *) = true
     * </pre>
     *
     * @param values  the values to test, may be {@code null} or empty
     * @return {@code true} if there is at least one {@code null} value in the array,
     * {@code false} if all the values are non-null.
     * If the array is {@code null} or empty, {@code true} is also returned.
     * @since 3.11
     */
    public static boolean anyNull(final Object... values) {
        return !allNotNull(values);
    }

    /**
     * Checks if all values in the given array are {@code null}.
     *
     * <p>
     * If all the values are {@code null} or the array is {@code null}
     * or empty, then {@code true} is returned, otherwise {@code false} is returned.
     * </p>
     *
     * <pre>
     * ObjectUtils.allNull(*)                = false
     * ObjectUtils.allNull(*, null)          = false
     * ObjectUtils.allNull(null, *)          = false
     * ObjectUtils.allNull(null, null, *, *) = false
     * ObjectUtils.allNull(null)             = true
     * ObjectUtils.allNull(null, null)       = true
     * </pre>
     *
     * @param values  the values to test, may be {@code null} or empty
     * @return {@code true} if all values in the array are {@code null}s,
     * {@code false} if there is at least one non-null value in the array.
     * @since 3.11
     */
    public static boolean allNull(final Object... values) {
        return !anyNotNull(values);
    }


    /**
     * {@code
     * 任何一个 无效 则抛异常
     * Long,Integer 类型,如果为0则异常
     * anyInvalid(*)             =  false
     * anyInvalid(*, *)          =  false
     * anyInvalid(*, *,1)        =  false
     * anyInvalid('0', *)        =  false
     * anyInvalid(null)          =  true
     * anyInvalid(*, 0)          =  true
     * anyInvalid(*, null)       =  true
     * anyInvalid(*, *, null, *) =  true
     * }
     * @param message
     * @param objects
     */
    public static boolean anyInvalid(Object... objects){
        if (objects==null) {
            return true;
        }
        for (Object obj : objects) {
            if(obj==null){
                return true;
            }
            if(obj instanceof Long&&obj.equals(0L)){
                return true;
            }
            if(obj instanceof Integer&&obj.equals(0)){
                return true;
            }
        }
        return false;
    }

    /**
     * 所有都无效
     * @param objects
     * @return
     */
    public static boolean allInvalid(Object... objects){
        return !anyValid(objects);
    }


    /**
     * {@code
     * 任何一个有效  数字0为无效
     * }
     * @param message
     * @param objects
     */
    public static boolean anyValid(Object... objects){
        if (objects==null) {
            return false;
        }
        for (Object obj : objects) {
            if(obj!=null){
                return true;
            }
            if(obj instanceof Long&&!obj.equals(0L)){
                return true;
            }
            if(obj instanceof Integer&&!obj.equals(0)){
                return true;
            }
        }
        return false;
    }
}
